﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;

public partial class Ticksys_ABM_Usuarios_Alta_Usuario : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            DataSet ds = CargarDDL.ConsultarSectores();

            BoxSector.DataSource = ds.Tables[0];
            BoxSector.DataValueField = "idSector";
            BoxSector.DataTextField = "Sector";
            BoxSector.DataBind();
        }
    }
 
    protected void ImageButton1_Click(object sender, ImageClickEventArgs e)
    {
        DataSet ds_verificar = AccesoDatos.Consulta("SELECT * FROM Usuarios WHERE Username = '" + BoxUsername.Text + "'");

        if (ds_verificar.Tables[0].Rows.Count != 0)
        {
            lbl_Existe.Visible = true;
            return;
        }
        Sector sector = new Sector();
        sector.idSector = BoxSector.SelectedValue;
        sector.sector = BoxSector.Text;
        Usuario usuario = new Usuario(BoxNombre.Text, BoxApellido.Text, BoxEmail.Text, BoxUsername.Text, BoxPassword.Text, BoxRol.SelectedValue, sector, BoxInterno.Text);

        GuardarEnBD.NuevoUsuario(usuario);
        Response.Redirect("Usuarios.aspx");
    }
}